package run.newbug.jt.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import run.newbug.jt.pojo.Item;
import run.newbug.jt.service.ItemService;
import run.newbug.jt.vo.ItemVO;
import run.newbug.jt.vo.PageResult;
import run.newbug.jt.vo.SysResult;

@RestController
@RequestMapping("item")
@CrossOrigin
public class ItemController {
    @Autowired
    private ItemService itemService;

    @GetMapping("getItemList")
    public SysResult getItemList(PageResult pageResult){
        return SysResult.succe(itemService.getItemList(pageResult));
    }

    @PutMapping("updateItemStatus")
    public SysResult updateItemStatus(@RequestBody Item item){
        itemService.updateItemStatus(item);
        return SysResult.succe();
    }

    @DeleteMapping("deleteItemById")
    public SysResult deleteItemById(Integer id){
        itemService.deleteItemById(id);
        return SysResult.succe();
    }

    @GetMapping("/{id}")
    public SysResult getById(@PathVariable Integer id){
        System.out.println(id);
        return SysResult.succe(itemService.getById(id));
    }

    @PutMapping("updateItem")
    public SysResult updateItem(@RequestBody Item item){
        System.out.println(item);
        itemService.updateItem(item);
        return SysResult.succe();
    }

    @PostMapping("saveItem")
    public SysResult saveItem(@RequestBody ItemVO itemVO){
        itemService.saveItem(itemVO);
        return SysResult.succe();
    }
}
